<template>
	<view class="container">
		<view class="cont">
			<image class="img" :src="img"></image>
		</view>
		<view v-if="type!=1">
			<view class="title title-one">恭喜你已经成功提交作答!</view>
			<view class="sub">注：考试成绩将在考试结束后统一给出</view>
		</view>
		<view v-else>
			<view class="title title-one">恭喜你</view>
			<view class="title title-two">已完成刷题<text class="num">{{finishedNum}}</text>遍</view>
			<button class="redo-btn" @click="redoSelf">再做一遍</button>
		</view>
		
	</view>

</template>

<script>
	import HomeService from '@/services/homepage/index';
	const homeService = new HomeService();
	export default {
		data() {
			return {
				img: '/static/exam/submit.png',
				type:0,
				delta:1,
				finishedNum:0,
				selfId:'',
				knowledgeId:'',
				ascription:'',
				totalProcess:0,
				isSecond:false
			}
		},
		onLoad(query){
		    this.type = query.type;
			this.finishedNum = parseInt(query.finishedNum)+1;
			this.delta = query.delta;
			this.selfId = query.selfId;
			this.knowledgeId = query.knowledgeId;
			this.ascription = query.ascription;
			this.totalProcess =  query.totalProcess;
			this.isSecond = query.isSecond
		},
		onBackPress(options) {
			if (options.from === 'navigateBack') {  
		        return false;  
		    }
		    uni.navigateBack({
		    	delta: Number(this.delta)
		    })
		    return true; 
		},
		methods:{
			redoSelf(){
				let self =  this;
				uni.showModal({
					content:'重置后可重新做题，确定重置吗？',
					success:(res)=>{
						if (res.confirm) {
							self.readRedoSelf();
						}
					}
				})
			},
			readRedoSelf(){
				const param = {
					selfId:this.selfId,
					knowledgeId:this.knowledgeId,
					ascription:this.ascription
				}
				homeService[this.isSecond?'redoSelfSub':'redoSelf'](param).then((response)=>{
					if(response.success){
						const {knowledgeId,totalProcess,ascription} = this;
						const selfId = response.result.selfId;
						const finishedNum = response.result.finishedNum;
						uni.redirectTo({
							url:`/pages/exam/selfExam?isSecond=${this.isSecond}&knowledgeId=${knowledgeId}&subjectNum=0&totalProcess=${totalProcess}&ascription=${ascription}&selfId=${selfId}&finishedNum=${finishedNum}`
						})
					}else{
						uni.showToast({
							title:response.message,
							icon:'none',
							duration:2000
						})
					}
					return false;
				});
				return false;
			}
		}
		
	}
</script>

<style lang='scss' scoped>
	.container {
		background: #fff;
	}

	.cont {
		text-align: center;
		margin-top: 150upx;
	}

	.img {
		width: 421upx;
		height: 400upx;
	}

	.title {
		color: #333;
		font-size: 32upx;
		font-weight: bold;
		text-align: center;
		&-one{
			margin: 40upx 0;
		}
		&-two{
			margin-bottom: 60upx;
		}
	}

	.sub {
		color: #666;
		font-size: 28upx;
		text-align: center;
	}
	
	.redo-btn{
		border: none;
		font-size: 32upx;
		color: #fff;
		background-color: #377cfd;
		width: 240upx;
		height: 80upx;
		line-height: 80upx;
	}
	.num{
		padding: 0 6upx;
		font-size: 46upx;
	}
</style>
